package com.hengxinguotong.zhihuichengjian.ui.lift.violation;

import android.os.Bundle;
import android.view.View;

import com.hengxinguotong.zhihuichengjian.R;
import com.hengxinguotong.zhihuichengjian.bean.LiftViolation;
import com.hengxinguotong.zhihuichengjian.ui.BaseActivity;
import com.hengxinguotong.zhihuichengjian.widget.font.HXTextView;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * @CopyRight 恒信国通信息科技
 * @Author WuLei
 * @Date 2019/2/24
 *
 * 升降机违章详情
 */

public class LiftViolationDetailActivity extends BaseActivity implements View.OnClickListener {
    @BindView(R.id.title_tv)
    HXTextView titleTv;
    @BindView(R.id.upload_time)
    HXTextView uploadTime;
    @BindView(R.id.lift_start_time)
    HXTextView liftStartTime;
    @BindView(R.id.lift_end_time)
    HXTextView liftEndTime;
    @BindView(R.id.driver_name)
    HXTextView driverName;
    @BindView(R.id.driver_no)
    HXTextView driverNo;
    @BindView(R.id.this_load)
    HXTextView thisLoad;
    @BindView(R.id.load_percent)
    HXTextView loadPercent;
    @BindView(R.id.lift_start_height)
    HXTextView liftStartHeight;
    @BindView(R.id.lift_stop_height)
    HXTextView liftStopHeight;
    @BindView(R.id.lift_trip_height)
    HXTextView liftTripHeight;
    @BindView(R.id.lift_direction)
    HXTextView liftDirection;
    @BindView(R.id.avg_speed)
    HXTextView avgSpeed;
    @BindView(R.id.max_x_tilt)
    HXTextView maxXTilt;
    @BindView(R.id.max_y_tilt)
    HXTextView maxYTilt;
    @BindView(R.id.load_person_count)
    HXTextView loadPersonCount;

    private LiftViolation liftViolation;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_lift_violation_detail);
        ButterKnife.bind(this);
        liftViolation = (LiftViolation) getIntent().getSerializableExtra("liftViolation");
        initView();
    }

    private void initView() {
        titleTv.setText(R.string.lift_violation_detail);

        uploadTime.setText(liftViolation.getAcquisitionTime());
        liftStartTime.setText(liftViolation.getBeginTime());
        liftEndTime.setText(liftViolation.getEndTime());
        switch (liftViolation.getWarningStatusPersons()){
            case 1://报警状态-身份认证 : 0身份认证未正常 1身份认证通过
                driverName.setText(liftViolation.getDriverName());
                driverNo.setText(liftViolation.getDriverCardNo());
                driverName.setTextColor(getmColor(R.color.color_666666));
                driverNo.setTextColor(getmColor(R.color.color_666666));
                break;
            case 0:
                driverName.setText("（身份未认证）");
                driverNo.setText("（身份未认证）");
                driverName.setTextColor(getmColor(R.color.color_D0021B));
                driverNo.setTextColor(getmColor(R.color.color_D0021B));
                break;
        }

        setmText(thisLoad, liftViolation.getWeight() + "千克", liftViolation.getWarningStatusWeight());//报警状态-重量 : 0重量正常 1重量预警 2重量报警
        setmText(loadPercent, liftViolation.getWeightPercent() + "%", liftViolation.getWarningStatusWeight());//报警状态-重量 : 0重量正常 1重量预警 2重量报警
        liftStartHeight.setText(liftViolation.getStartHeight() + "米");
        liftStopHeight.setText(liftViolation.getEndHeight() + "米");
        setmText(liftTripHeight, liftViolation.getTripHeight() + "米", liftViolation.getWarningStatusHeight());//报警状态-高度 : 0高度正常 1高度预警 2高度告警
        switch (liftViolation.getLiftingDirection()){
            case 0://起升方向 2为上 1为下 0为静止
                liftDirection.setText("静止");
                break;
            case 1:
                liftDirection.setText("下");
                break;
            case 2:
                liftDirection.setText("上");
                break;
        }
        setmText(avgSpeed, liftViolation.getAvgSpeed() + "米/秒", liftViolation.getWarningStatusSpeed());//	报警状态-速度 : 0速度正常 1速度预警 2速度报警

        setmText(maxXTilt, liftViolation.getMaxXTilt() + "度", liftViolation.getWarningStatusTilt());//报警状态-倾斜 : 0 倾斜正常 1倾斜预警 2倾斜报警
        setmText(maxYTilt, liftViolation.getMaxYTilt() + "度", liftViolation.getWarningStatusTilt());//报警状态-倾斜 : 0 倾斜正常 1倾斜预警 2倾斜报警
        switch (liftViolation.getWarningStatusPersons()){
            case 0://	报警状态-人数 : 0人数正常 1人数超载
                loadPersonCount.setText(liftViolation.getLoadPersons() + "人");
                loadPersonCount.setTextColor(getmColor(R.color.color_666666));
                break;
            case 1:
                loadPersonCount.setText(liftViolation.getLoadPersons() + "人（超载）");
                loadPersonCount.setTextColor(getmColor(R.color.color_D0021B));
                break;
        }

    }

    @OnClick({R.id.back_tv})
    public void onClick(View v) {
        switch (v.getId()){
            case R.id.back_tv:
                finish();
                break;
        }
    }

    private void setmText(HXTextView textView, String text, int status){
        switch (status){
            case 0:
                textView.setText(text);
                textView.setTextColor(getmColor(R.color.color_666666));
                break;
            case 1:
                textView.setText(text + "（预警）");
                textView.setTextColor(getmColor(R.color.color_FD9D00));
                break;
            case 2:
                textView.setText(text + "（报警）");
                textView.setTextColor(getmColor(R.color.color_D0021B));
                break;
        }
    }

    private int getmColor(int colorId){
        return getResources().getColor(colorId);
    }
}
